<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        var convert = function (s, numRows) {
            if (numRows === 1) return s
            let n = 0;
            let dir = 1;
            let arr = []
            for (let k of s) {
                if (!arr[n]) arr[n] = ''
                arr[n] += k
                n += dir;
                if (n === 0 || n === numRows - 1) {
                    dir = -dir
                }
            }
            let str = arr.join('')
            return str
        };

        console.log(convert("AB", 1))
    </script>
</body>

</html>